package com.jiandaoshou;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.jiandaoshou.base.BaseActivity;
import com.jiandaoshou.entry.OrderDetailInfo;
import com.jiandaoshou.http.APIDefine;
import com.jiandaoshou.http.Http;
import com.jiandaoshou.utils.JsonUtil;
import com.jiandaoshou.utils.LogUtil;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;

public class JinRiDingDetailAct extends BaseActivity {
    private String strOrderID;
    private String strPayMode;
    private String strCount;
    private String strTime;
    //订单号
    private TextView Tv_OrderID;
    //订单价格
    private TextView Tv_OrderPrice;
    //支付方式
    private TextView Tv_OrderPayMode;
    //商品序号
    private TextView Tv_ShopNum;
    //商品名称
    private TextView Tv_ShopName;
    //订单量
    private TextView Tv_OrderNum;
    //订单价格
    private TextView Tv_ShopPirce;
    //订单支付方式
    private TextView Tv_shopPayMode;
    //订单下单时间
    private TextView Tv_DingDanTime;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            OrderDetailInfo Info= (OrderDetailInfo) msg.obj;
            switch (msg.what){
                case 0:
                    Tv_OrderID.setText(strOrderID);
                    Tv_OrderPrice.setText(strCount);
                    Tv_ShopNum.setText(Info.getStrOrderID());
                    Tv_ShopName.setText(Info.getStrWaresName());
                    Tv_OrderNum.setText("*"+Info.getnWaresCount());
                    Tv_ShopPirce.setText(Info.getStrWaresPrice()+" 元");
                    if(strPayMode.equals("1")){
                        Tv_shopPayMode.setText("微信支付");
                        Tv_OrderPayMode.setText("微信支付");
                    }else if(strPayMode.equals("2")){
                        Tv_shopPayMode.setText("支付宝支付");
                        Tv_OrderPayMode.setText("支付宝支付");
                    }else if(strPayMode.equals("3")){
                        Tv_shopPayMode.setText("pos机支付");
                        Tv_OrderPayMode.setText("pos机支付");
                    }else if(strPayMode.equals("4")){
                        Tv_shopPayMode.setText("苹果支付");
                        Tv_OrderPayMode.setText("苹果支付");
                    }else if(strPayMode.equals("5")){
                        Tv_shopPayMode.setText("银联支付");
                        Tv_OrderPayMode.setText("银联支付");
                    }
                    Tv_DingDanTime.setText("日期:"+strTime);
                    break;
            }
        }
    };
    @Override
    public boolean showBackLogo() {
        return true;
    }

    @Override
    protected int getContentViewRes() {
        return R.layout.activity_jinriding_detail;
    }

    @Override
    protected String getTitleText() {
        return "订单详情";
    }

    @Override
    public void init() {
        getToolbar().setNavigationIcon(R.drawable.selector_tab_btn);
        //获取订单的ID
        strOrderID = getIntent().getStringExtra("OrderID");
        strPayMode=getIntent().getStringExtra("payMode");
        strCount=getIntent().getStringExtra("aount");
        strTime=getIntent().getStringExtra("time");
        initId();
        //获取数据
        HashMap<String, String> map = new HashMap<>();
        map.put("strOrderID",strOrderID);
        Http.post(APIDefine.TF_Interface_GetOrderDetailMsg, map, new Http.HttpCallBack() {
            @Override
            public void onHttpSuccess(String response) throws Exception {
                JSONObject object=new JSONObject(response);
                JSONArray array= (JSONArray) object.get("OrderDetailList");
                OrderDetailInfo Info=null;
                for(int i=0;i<array.length();i++){
                    Info= JsonUtil.parser.fromJson(array.get(i).toString(),OrderDetailInfo.class);
                }
                Message msg=handler.obtainMessage();
                msg.obj=Info;
                msg.what=0;
                msg.sendToTarget();
            }
        });
    }

    private void initId() {
         Tv_OrderID = $(R.id.detail_orderid);
         Tv_OrderPrice = $(R.id.detail_price);
         Tv_OrderPayMode = $(R.id.detail_paymode);
         Tv_ShopNum = $(R.id.detail_warenum);
         Tv_ShopName = $(R.id.detail_name);
         Tv_OrderNum = $(R.id.detail_ordernum);
         Tv_ShopPirce = $(R.id.detail_orderprice);
         Tv_shopPayMode = $(R.id.detail_orderpaymode);
         Tv_DingDanTime=$(R.id.detail_ordertime);
    }
}
